package com.eamois.dao.graph.impl;

import java.sql.SQLException;
import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.eamois.dao.graph.GraphJobCardDao;
import com.eamois.dao.impl.BaseDaoImpl;
import com.eamois.domain.graph.GraphJobCard;
import com.eamois.domain.graph.GraphTechnologyType;

public class GraphJobCardDaoImpl extends BaseDaoImpl<GraphJobCard> implements
		GraphJobCardDao {

	@Override
	@SuppressWarnings("unchecked")
	public Collection<GraphJobCard> findAll() {
		// TODO Auto-generated method stub
		return (Collection<GraphJobCard>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(GraphJobCard.class);
				return criteria.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<GraphJobCard> findJobCardByTech(final GraphTechnologyType graphTechnologyType) {
		// TODO Auto-generated method stub
		return (Collection<GraphJobCard>) this.getHibernateTemplate().execute(new HibernateCallback() {

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				Criteria criteria = arg0.createCriteria(GraphJobCard.class);
				criteria.add(Restrictions.eq("graphTechnology", graphTechnologyType));
				return criteria.list();
			}
		});
	}

	

}
